#include<stdio.h>
int main()
{
    int a = 10;
    while(a--)
    {
        int n;
        int sum = 0;
        scanf("%d",&n);
        if(n==0)
        {
            break;
        }
        while(n/3)
        {
            sum += n/3;
            n = n/3+n%3;
        }
        if(n==2)
        {
            printf("%d\n",sum+1);
        }
        else
        {
            printf("%d\n",sum);
        }
    }
    return 0;
}